package com.ruoyi.base.factory;

import com.ruoyi.base.enums.item.OreEnum;
import com.ruoyi.base.enums.item.PlanetaryMaterialsEnum;
import com.ruoyi.base.enums.item.RawOreEnum;
import com.ruoyi.base.enums.type.ItemTypeEnum;
import com.ruoyi.base.exception.CustomException;
import com.ruoyi.business.pojo.item.ItemDTO;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 项目工厂
 * @author Administrator
 */
public class ItemFactory {
    /**
     * 根据类型获取项目列表
     */
    public static List<ItemDTO> getByCode(int typeCode) {
        ItemTypeEnum type = Optional.ofNullable(ItemTypeEnum.ofCode(typeCode)).orElseThrow(() -> new CustomException("类型不存在"));

        if (type == ItemTypeEnum.sthj) {
            return Arrays.stream(OreEnum.values()).map(x -> new ItemDTO(x.getCode(), x.getName())).collect(Collectors.toList());
        }
        if (type == ItemTypeEnum.ljtnj) {
            return Arrays.stream(PlanetaryMaterialsEnum.values()).map(x -> new ItemDTO(x.getCode(), x.getName())).collect(Collectors.toList());
        }
        if (type == ItemTypeEnum.twjhw) {
            return Arrays.stream(RawOreEnum.values()).map(x -> new ItemDTO(x.getCode(), x.getName())).collect(Collectors.toList());
        }

        throw new CustomException("类型不存在");
    }
}
